package com.qqtech.qquan.sms.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.agent.context.AdminPage;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.sms.model.SmsSysParam;
import com.qqtech.qquan.sms.model.SmsSysParamQuery;
import com.qqtech.qquan.sms.model.SmsSysParamVo;
import com.qqtech.qquan.sms.service.SmsSysParamService;
import com.qqtech.qquan.sys.controller.BaseAgentController;

@Controller
@RequestMapping(value = "/sms/sys/param")
public class SmsSysParamController extends BaseAgentController {
	@Resource
	private SmsSysParamService smsSysParamService;

	@Override
	protected BaseService<SmsSysParam> getBaseService() {
		return smsSysParamService;
	}

	/**
	 * 列表页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list() {
		return "/sms/sysParam-list";
	}

	/**
	 * 列表
	 * 
	 * @param sysRoleQuery
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public AdminPage list(SmsSysParamQuery smsSysParamQuery, HttpServletRequest request, HttpServletResponse response) {
		AdminPage adminPage = new AdminPage();
		Pageable pageKit = new PageKit(smsSysParamQuery.getPage(), new PageOrder(Direction.ASC, "id"));
		Page<SmsSysParamVo> page = smsSysParamService.queryPageList(smsSysParamQuery, pageKit);
		adminPage.setRows(page.getContent());
		adminPage.setTotal(page.getNumberOfElements());
		return adminPage;

	}

	/**
	 * 去更新
	 * 
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/toUpdate")
	public String toUpdate(Integer id, Model model) {
		SmsSysParamVo updateVo = smsSysParamService.getById(id);
		model.addAttribute("updateVo", updateVo);
		return "/sms/sysParam-update";
	}

	/**
	 * 更新
	 * 
	 * @param shareId
	 * @return
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public Result update(SmsSysParam smsSysParam) {
		Result ret = new Result();
		smsSysParamService.updateById(smsSysParam);
		return ret;
	}
}
